const cosmiconfig = require('cosmiconfig');
 
// 读取配置
async function getConfig(moduleName) {
  const explorer = cosmiconfig(moduleName);
  const result = await explorer.search();
  return result ? result.config : {};
}
 
// 写入配置
async function setConfig(moduleName, newConfig) {
  const explorer = cosmiconfig(moduleName);
  const currentConfig = await explorer.search() || {};
  const mergedConfig = { ...currentConfig.config, ...newConfig };
  await explorer.create(mergedConfig);
}
 
module.exports = {
  getConfig,
  setConfig
};